package com.zzw.hj65;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @Project: hw_java
 * @Description: 查找两个字符串a, b中的最长公共子串
 * @Author: zzw
 */
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line1 = br.readLine();
        String line2 = br.readLine();

        // 找出短的字符串
        String minLenStr = line1.length() <= line2.length() ? line1 : line2;
        String maxLenStr = line1.length() > line2.length() ? line1 : line2;

        // 最大子串
        String maxSubStr = "";
        for (int i = 0; i < minLenStr.length(); i++) {
            for (int j = i + 1; j <= minLenStr.length(); j++) {
                String sub1 = minLenStr.substring(i, j);
                if (maxLenStr.contains(sub1) && sub1.length() > maxSubStr.length()) {
                    maxSubStr = sub1;
                }
            }
        }

        System.out.println(maxSubStr);
    }
}